package com.wngbms.netty.seatdemo.comm;

public enum CmdType {

    HEARTBEAT((byte) 0b000000, (byte) 6, "心跳"),
    CONNECT((byte) 0b0000001, (byte) 6, "建立连接"),
    EVENT((byte) 0b000010, (byte) 6, "推送事件"),
    EXTRA_INFO((byte) 0b000011, (byte) 6, "推送额外补充信息"),
    HANGUP((byte) 0b000100, (byte) 6, "挂断"),
    OWNER_SEARCH((byte) 0b000101, (byte) 6, "业主信息查询"),
    ECHO((byte) 0b111101, (byte) 6, ""),
    BINARY_TEST_DOWNLOAD((byte) 0b111110, (byte) 6, "二进制大文件网络传输测试, 客户端下载测试"),
    BINARY_TEST_UPLOAD((byte) 0b111111, (byte) 6, "二进制大文件网络传输测试, 客户端上传测试"),

    ;
    byte type;
    byte bitLen; // 占用的比特位数
    String desc;

    CmdType(byte type, byte bitLen, String desc) {
        this.type = type;
        this.bitLen = bitLen;
        this.desc = desc;
    }

    public byte getType() {
        return type;
    }

    public void setType(byte type) {
        this.type = type;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static CmdType find(byte val) {
        CmdType[] values = CmdType.values();
        for (int i = 0; i < values.length; i++) {
            if (values[i].getType() == val) {
                return values[i];
            }
        }
        return null;
    }
}
